"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitUtil = void 0;
class BitUtil {
    //index是二进制从右到左
    static isBitSet(value, index) {
        if (isNaN(value)) {
            return false;
        }
        let str = value.toString(2);
        // Logger.log("isBitSet===", str, index);
        if (parseInt(str[str.length - 1 - index]) == 1) {
            // Logger.log("isBitSet===", str, index);
            return true;
        }
        return false;
    }
    //从右到左计算
    static setBitValue(value, index) {
        let str = value.toString(2);
        let strArr = str.split("");
        let offestLen = index - strArr.length + 1;
        if (offestLen > 0) {
            for (let i = 0; i < offestLen; i++) {
                strArr.unshift("0");
            }
        }
        let setIndex = (strArr.length - index - 1);
        strArr[setIndex] = "1";
        let newStr = "";
        for (let i = 0; i < strArr.length; i++) {
            newStr += strArr[i];
        }
        // Logger.log("setBitValue==", str, index, newStr)
        let newValue = parseInt(newStr, 2);
        return newValue;
    }
    static clearBitValue(value, index) {
        let str = value.toString(2);
        let newStr = "";
        for (let i = 0; i < str.length; i++) {
            if (i == (str.length - index - 1)) {
                newStr = newStr + "0";
            }
            else {
                newStr = newStr + str.charAt(i);
            }
        }
        let newValue = parseInt(newStr, 2);
        return newValue;
    }
}
exports.BitUtil = BitUtil;
